class Plusgstest {
  constructor(options) {
    this.deletePages = [];
    this.tip = options.tip;
    options.pages.forEach((item) => {
      this.deletePages.push(item.template.substring(item.template.lastIndexOf('/') + 1));
    });
    // this.deletePages = options.pages;
  }
  apply (compiler) {
    compiler.hooks.done.tap('Plusgstest', (
      stats /* 在 hook 被触及时，会将 stats 作为参数传入。 */
    ) => {
      if (this.deletePages.length > 0) {
        console.log('删除多余文件完成：' + this.deletePages.join(','));
        console.log(this.tip);
      }
    });
    // compiler.hooks.assetEmitted.tap(
    //   'Plusgstest',
    //   (file, { content, source, outputPath, compilation, targetPath }) => {
    //     console.log(file);
    //     // if (this.deletePages.includes(file)) {
    //     //   console.log(true);
    //     // }
    //   }
    // );
    compiler.hooks.emit.tap('Plusgstest', (compilation) => {
      // console.log(compilation);
      this.deletePages.forEach((item => {
        delete compilation.assets[item];
      }));
      // console.log('删除多余文件完成：' + this.deletePages.join(','));
    });
  }
}


module.exports = Plusgstest;
